import Taro ,{ Component } from '@tarojs/taro'
import {base_url} from "../network/config";
import DataManager from "../utils/DataManager";


export default class BasePage extends Component{

  constructor(){
    super(...arguments)
  }

  componentWillMount(){
    Taro.showShareMenu({
      withShareTicket: true
    })
  }

  onShareAppMessage(options){
    console.log('   base----   options    ' + JSON.stringify(options));

    if (!options.target){
      return;
    }

    let itemShareId = options.target.dataset.itemid
    let itemShareType = options.target.dataset.itemtype;

    if (options.from == 'button' && itemShareId && itemShareType){

      let pageUrl;
      if (itemShareType == 1) {
        pageUrl = `/pages/job/jobDetail?jobId=` + itemShareId + `&shareUserId=` + DataManager.getUserId();
      } else if (itemShareType == 2){
        pageUrl = `/pages/car/carDetail?carId=` + itemShareId + `&shareUserId=` + DataManager.getUserId();
      } else if (itemShareType == 3){
        pageUrl = `/pages/shop/shopDetail?shopId=` + itemShareId + `&shareUserId=` + DataManager.getUserId();
      }

      // 转发成功
      let url = base_url + 'rest/user/share/save';
      Taro.request({
        url:url,
        data: {
          token:DataManager.getToken(),
          platform:'android_c',
          weixinId:DataManager.getWeiXinId(),
          loginChannel:'c',
          appId:'KC876D98B30UA40CJSNHI689FB33SDW',
          digest : 'dda484557c12febe48139d8f44051c13',
          id:itemShareId,
          type:itemShareType,
        },
        header: { 'content-type': 'application/x-www-form-urlencoded' },
        method: 'POST',
        success(res) {
        }
      })

      return {
        path: pageUrl,
      }
    }
  }

}


